<template>
	<view class="container" v-if="isLoaded">
		<!-- 表单 -->
		<view class="content">
			<form class="l-form">
				<view class="l-form-item">
					<view class="l-lbl">类型:</view>
					<view class="l-form-right picker">
						<picker @change="bindPickerChange" :value="'value'" :range="remarkTypeEnum" :range-key="'text'" disabled>
							<view>{{ remarkTypeEnum.find((item) => item.value == form.type).text }}</view>
						</picker>
					</view>
				</view>

				<view class="l-form-item">
					<view class="l-lbl">内容:</view>
					<view class="l-form-right l-form-input">
						<textarea class="l-textarea" v-model="form.content" :maxlength="50" />
					</view>
				</view>
			</form>
		</view>

		<li-bottom-btns mode="add" @btnEditOrSaveSubmitClick="btnSubmitClick" />
	</view>
</template>
<script>
import { AddFoodTag } from '@/common/api.js';
import { uShowLoading, uHideLoading, uNavigateTo, umodal, utoast } from '../../../utils/uniUtils.js';
import checker from '../../../common/graceChecker';
import { remarkTypeEnum } from '../../../constants/normalConstants.js';
import { toastIconEnum } from '../../../constants/uiConstants.js';
import { corpId, storeId } from '../../../constants/apiConstants';
export default {
	async onLoad(options) {
		this.form.type = options.type ?? 1;
	},

	async mounted() {
		try {
			uShowLoading();
		} catch (error) {
			console.log('error', error);
		} finally {
			this.isLoaded = true;
			uHideLoading();
		}
	},
	data() {
		return {
			id: null,
			isLoaded: false,
			form: {
				type: 1,
				content: '',
				corpId: corpId,
				storeId: storeId
			},
			rules: [], //表单校验规则
			remarkTypeEnum,
			lock: false // 节流锁
		};
	},

	methods: {
		bindPickerChange(e) {
			this.form.type = this.remarkTypeEnum[e.detail.value].value;
		},
		async insertData() {
			return AddFoodTag(this.form);
		},
		async btnSubmitClick() {
			if (!(await umodal('确认要提交吗？'))) {
				return;
			}
			// 表单校验

			//  提交表单
			const res = await this.insertData(this.form);
			if (res?.code == 0) {
				await utoast('操作成功');
				setTimeout(() => {
					uNavigateTo('/pages/workbench/remark/list');
				}, 1000);
			} else {
				setTimeout(() => {
					console.log('fail', this.lock);
				}, 2000);
			}
		}

		//方法放上面
	}
};
</script>
<style lang="scss" scoped>
@import '~@/static/styles/commonStyle.scss';
.container {
	.content {
		padding: 10px;
	}
}
</style>
